package pers.bbw.crr.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import pers.bbw.crr.dao.ActivityMapper;
import pers.bbw.crr.dto.ActivitySearchDto;
import pers.bbw.crr.entity.Activity;
import pers.bbw.crr.service.ActivityService;
import pers.bbw.crr.vo.ActivityVo;

import javax.annotation.Resource;
import java.util.Date;

/**
 * activityService业务层处理
 *
 * @author bbw
 * @date 2024-12-13
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Resource
    private ActivityMapper activityMapper;

    /**
     * 查询activity
     * v
     * @param id activity主键
     * @return activity
     */
    @Override
    public ActivityVo selectActivityById(int id) {
        Activity activity = activityMapper.selectActivityById(id);
        ActivityVo activityVo = new ActivityVo();
        BeanUtil.copyProperties(activity, activityVo, true);
        return activityVo;
    }

    /**
     * 查询活动列表
     * @author 白博文 0205
     * @param dto 活动信息数据传输对象
     * @return activity
     */
    @Override
    public PageInfo<ActivityVo> selectActivityList(ActivitySearchDto dto) {
        Activity activity = new Activity();
        BeanUtil.copyProperties(dto, activity);
        PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        PageInfo<ActivityVo> activityPageInfo = new PageInfo<>(activityMapper.selectActivityList(activity));
        return activityPageInfo;
    }

    /**
     * 新增activity
     * @author 白博文 0205
     * @param activity activity
     * @return 结果
     */
    @Override
    public int insertActivity(Activity activity) {
        activity.setState(0);
        return activityMapper.insertActivity(activity);
    }

    /**
     * 修改activity
     * @author 白博文 0205
     * @param activity activity
     * @return 结果
     */
    @Override
    public int updateActivity(Activity activity) {
        activity.setUpdateTime(new Date());
        return activityMapper.updateActivity(activity);
    }

    /**
     * 批量删除activity
     * @author 白博文 0205
     * @param ids 需要删除的activity主键
     * @return 结果
     */
    @Override
    public int deleteActivityByIds(int[] ids) {
        return activityMapper.deleteActivityByIds(ids);
    }

    /**
     * 删除activity信息
     * @author 白博文 0205
     * @param id activity主键
     * @return 结果
     */
    @Override
    public int deleteActivityById(int id) {
        return activityMapper.deleteActivityById(id);
    }

}
